#pragma once

#ifndef _STRUCTS_H_
#define _STRUCTS_H_

#define N 16

#include <time.h>
#include <vector>

//stub
class CLinkshell;
class CChar;
class CBaseEntity;

struct connections {
	SOCKET lobbySocket;
	SOCKET polSocket;
	SOCKET outSocket;
	SOCKET acctSocket;
	u_short udpPort;
	unsigned int acctID;
    unsigned int clientIP;
	unsigned int servIP;
	char newCharName[16];
	unsigned int time;
};

struct skills {
	union {
		struct {
			// skillId 0
			unsigned short unknown1;
			// skillId 1 - 12
			unsigned short h2h, dagger, sword, gsword, axe, gaxe, scythe, polearm, katana, gkatana, club, staff;
			// skillId 13 - 24
			unsigned short reserved1[12];
			// skillId 25 - 33
			unsigned short archery, marksmanship, throwing, guarding, evasion, shield, parrying, divine, healing;
			// skillId 34 - 43
			unsigned short enhancing, enfeebling, elemental, dark, summoning, ninjutsu, singing, string, wind, blue;
			// skillId 44 - 47
			unsigned short reserved2[4];
			// skillId 48 - 54
			unsigned short fishing, woodworking, smithing, goldsmithing, clothcraft, leathercraft, bonecraft;
			// skillId 55 - 57
			unsigned short alchemy, cooking, riding;
			// skillId 58 - 62
			unsigned short reserved3[5];
			// skillId 63
			unsigned short unknown2;
		};
		// index skillId 0 - 63
		unsigned short skillId[64];
	};
	// ranks only used for crafting.  size 64 for convenience
	unsigned char rank[64];
};

struct look {

	union {
		struct {

			unsigned char face, race;

			unsigned short head, body, hands, legs, feet, main, sub, range;

		};
		unsigned short slot[9];
	};

};

struct position {

	unsigned short rotation;

	float x, y, z;

};

struct pathnode {

	unsigned short rotation;

	float x, y, z;

};

struct roamnode {

	unsigned short rotation;

	float x, y, z;

	bool occupied;

};

/*struct spawnpoint {

	int id;

	// list of waypoint nodes for NPCs and MOBs to roam
	std::vector<struct roamnode> nodeList;

	time_t	nm_lastspawntime;

};*/


struct location {

	struct position p;

	unsigned char zone, prevzone;

};

struct jobs {

	unsigned long unlocked;

	union {
		struct {
			unsigned char reserved, war, mnk, whm, blm, rdm, thf, pld, drk, bst, brd, rng, sam, nin, drg, smn, blu, cor, pup, dnc, sch;
		};
		unsigned char job[21];
	};
};

struct blowfish {

	unsigned int key[5];

	unsigned char hash[16];
	
	unsigned long P[18], S[4][256];

};


// Used for the recastlist
struct spellRecast {
	unsigned short spellID;
	int timeStamp;
	double recast;
};

// Used for the recastlist
struct abilityRecast {
	unsigned short abilityID;
	int timeStamp;
	double recast;
	int recastID;
};


/*struct identification {

	unsigned int  charid, ip, servip;

	unsigned int  acctid;

	unsigned short targid;

	char charname[16];

};*/

struct regions {
	int ID;
	float x1, x2, y1, y2, z1, z2;
};

struct health {

	short hp, mp, tp;

	unsigned char hpp, mpp;

	unsigned char animation;

	unsigned int flags;

	unsigned char nameFlag;

};

struct healthMob {

	int hp, mp, tp;

	unsigned char hpp, mpp;

	unsigned char animation;

	unsigned int flags;

	unsigned char nameFlag;

};

struct nation {

	unsigned char home;

	unsigned char rank[3];

	unsigned int rankpoints[3];

};

struct sAction { 
	unsigned short type:8,size:8;
	unsigned short parent;
	unsigned char unk1:8;
	unsigned int CasterID;
	unsigned int unk2;
	unsigned int unk3;
	unsigned char unk4;
	unsigned int unk4_1 : 6;
	unsigned int TargetID : 26;
	unsigned int unk5;
	unsigned int unk8 : 3;
	unsigned int Result : 16;
	unsigned int unk7 : 1;
	unsigned int Type : 4;
	unsigned int ResultType : 8;
};

struct sActionTwo {
	unsigned int unk4_1 : 6;
	unsigned int TargetID : 26;
	unsigned int unk5;
	unsigned int unk8 : 3;
	unsigned int Result : 16;
	unsigned int unk7 : 1;
	unsigned int Type : 4;
	unsigned int ResultType : 8;
};

struct stats {

	short str,dex,vit,agi,inte,mnd,chr;

	short pStr,pDex,pVit,pAgi,pInt,pMnd,pChr;

};

struct resist { //For players, it's just the elemental resist displayed on screen.  Otherwise, this is for final mob dmg mods.

	float fire,ice,wind,earth,thunder,water,light,dark;

	float slash,pierce,handtohand,impact,range;

};

struct elements {

	unsigned short fire, ice, wind, earth, lightning, water, light, dark;

};

struct keyitems {

	 unsigned char keyList[0x100];

	 unsigned char seenList[0x100];

};

struct spells {

	 unsigned char spellList[0x100];

};

struct timer {

	time_t	timestamp;
	int		timetowait;
	LPVOID	* ptr;
	unsigned short type;

};

struct transport {
	time_t	timestamp;
	int		action;
	unsigned short tID;
};

struct UDPdata {
	int command, status, result;
	unsigned short nextzone;
	char * key;
};


struct seaPacket 
{
	short pSize;

	unsigned char nameLen;

	char name[16];

	char key1[4],key2[4];

	unsigned char fromLvl,toLvl;

	unsigned char areaCount;

	unsigned char areas[10]; //I think 6 - 7 should be enough, but i didn't test all regions

	unsigned char job;

	unsigned char fromRank,toRank;

	unsigned int comment;

	unsigned short flags1;

	unsigned int flags2;

	unsigned char country;

	unsigned char race;

	//Sorting Params, 0 = sort Ascending, 1 = sort Descending
	
	unsigned char sortDescendingByName;

	unsigned char sortDescendingByRank;

	unsigned char sortDescendingByLevel;

	unsigned char sortDescendingByRace;

	unsigned char sortDescendingByFlags;

	unsigned char sortDescendingByJob;

	unsigned int lsId;
	CLinkshell* ls;

	//This is the target ID of the person calling the party search
	unsigned short partyId;

	bool getActiveLS;
};

struct seaResponseEntry
{
	char name[16];

	unsigned char mainjob;
	unsigned char mainjobLevel;

	unsigned char subjob;
	unsigned char subjobLevel;

	unsigned char country;
	unsigned char rank;

	unsigned char race;

	unsigned char area;

	unsigned short flags1;

	unsigned int flags2;

	unsigned int comment;

	unsigned int unknown0x08;

	unsigned char linkshellRank;

	unsigned int unknown0x0E;

	unsigned short languages;
};

struct eventQueue {
	
	char eventScript[255];
	
	char eventScriptFunction[255];
	
	unsigned int inEvent;

	void reset() {
		memset(eventScript, 0, 255);
		memset(eventScriptFunction, 0, 255);
		sprintf(eventScriptFunction, "none");
		inEvent = 0;
	}
};


struct weather {
	unsigned int changeTime;
	unsigned short weatherEffect;
};

struct zoneMusic {
	unsigned char m_song1;
	unsigned char m_song2;
	unsigned char m_bSongS;
	unsigned char m_bSongM;
};

struct zoneWeather {
	struct weather m_lastWeather;
	struct weather m_currentWeather;
	unsigned long long m_nextWeatherChange;
};

struct zoneLine {
	struct position m_toPos;
	unsigned char m_toZone;
	unsigned char m_zoneLineIdent[4];
};

struct enmityVC {
	CBaseEntity * m_pEntity;
	float m_vEnmity;
	float m_cEnmity;
};

#endif
